<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Session\Store;


class LoginController extends Controller
{
    public function __construct()
    {

    }

    public function index(Request $request)
    {
        if ($_SERVER['HTTP_HOST'] != '47.107.94.222') {
            echo '';die;
        }
        if ($request->session()->has('lqy_user_id')) {
            $request->session()->pull('lqy_user_id');
        }
        return view('login/index');
    }

    public function login(Request $request)
    {
        if ($request->isMethod('POST')) { //判断文件是否是 POST的方式上传

            $username = empty($request['username']) ? '' : $request['username'];
            $password = empty($request['password']) ? '' : $request['password'];

//            $country = ShortController::getRemoteCountry($_SERVER['REMOTE_ADDR']);
//            $city = ShortController::getRemoteCity($_SERVER['REMOTE_ADDR']);
//            if ($country == '中国' || in_array($city, ['香港', '澳门', '台湾'])) {
//                response_json(1, '当前区域限制登录！');
//            }

            if ($username !== 'myadmin') {
                response_json(1, '账号不存在，请重新输入！');
            }
            if ($password !== 'my123456') {
                response_json(1, '密码有误，请重新输入！');
            }

            $request->session()->put('lqy_user_id', 123);
            $request->session()->save();
            response_json(0, '登录成功！');
        }
    }
}
